<?

require_once ("util/Transformer.php");
require_once ("util/Generator.php");
require_once ("dao/MadDAO.php");


class ActionSalvarFormulario {

	public function show()
	{

		$transformer = new Transformer();
		$generator = new Generator();
		$transformer->setDirFisicoTemplates("template/");
		$transformer->setArquivoTemplate("esqueletoBase.htm");
		$valoresTroca = array ();
		$valoresTroca["titulo"] = $this->getTitulo();
		$valoresTroca["footer"] = $generator->getFooter();
		$valoresTroca["erro"] = $generator->getErro();
		$valoresTroca["body"] = $this->getBody();
		$transformer->setValoresTroca($valoresTroca);
		$saida = $transformer->processaHTML();
		echo $saida;
	}

	private function getTitulo()
	{
		$titulo = "SIMweb :: Pesquisa MAD";
		return $titulo;
	}



	private function getBody() {
	//ver($_REQUEST);

		$MadDao = new MadDAO();

	
		function Tamanho($val)
		{
			if(strlen($val) >= 2)
			{
				$r = $val;
			}
			else
			{
				$r = $val ." ";
			}

			return $r;
		}
		//Mao direita

		$seqDirClass = Tamanho($_REQUEST['comboClass1']).Tamanho($_REQUEST['comboClass3']).Tamanho($_REQUEST['comboClass5']).Tamanho($_REQUEST['comboClass7']).Tamanho($_REQUEST['comboClass9']);

		//----------------------

		$seqDirSubClass = Tamanho($_REQUEST['comboSubClass1']).Tamanho($_REQUEST['comboSubClass3']).Tamanho($_REQUEST['comboSubClass5']).Tamanho($_REQUEST['comboSubClass7']).Tamanho($_REQUEST['comboSubClass9']);

		//----------------------------

		//$seqDirPtoCarac = Tamanho($_REQUEST['comboPtoCarac1']).Tamanho($_REQUEST['comboPtoCarac3']).Tamanho($_REQUEST['comboPtoCarac5']).Tamanho($_REQUEST['comboPtoCarac7']).Tamanho($_REQUEST['comboPtoCarac9']);



		//------------------
		//Mao Esquerda
		//------------------


		$seqEsqClass    = Tamanho($_REQUEST['comboClass2']).Tamanho($_REQUEST['comboClass4']).Tamanho($_REQUEST['comboClass6']).Tamanho($_REQUEST['comboClass8']).Tamanho($_REQUEST['comboClass10']);

		//----------------------

		$seqEsqSubClass = Tamanho($_REQUEST['comboSubClass2']).Tamanho($_REQUEST['comboSubClass4']).Tamanho($_REQUEST['comboSubClass6']).Tamanho($_REQUEST['comboSubClass8']).Tamanho($_REQUEST['comboSubClass10']);

		//----------------------------

		//$seqEsqPtoCarac = Tamanho($_REQUEST['comboPtoCarac2']).Tamanho($_REQUEST['comboPtoCarac4']).Tamanho($_REQUEST['comboPtoCarac6']).Tamanho($_REQUEST['comboPtoCarac8']).Tamanho($_REQUEST['comboPtoCarac10']);


		//-------------------------------------------------
		//atualizacao dos campos serie_pri_duvida e secao_pri_duvida



		//SERIE_PRI_DUVIDA


		if($_REQUEST['checkClass1']!="")
		{
			$StrClass1="?";
		}
		else
		{
			$StrClass1="-";
		}

		if($_REQUEST['checkClass3']!="")
		{
			$StrClass1=$StrClass1."?";
		}
		else
		{
			$StrClass1=$StrClass1."-";
		}

		if($_REQUEST['checkClass5']!="")
		{
			$StrClass1=$StrClass1."?";
		}
		else
		{
			$StrClass1=$StrClass1."-";
		}

		if($_REQUEST['checkClass7']!="")
		{
			$StrClass1=$StrClass1."?";
		}
		else
		{
			$StrClass1=$StrClass1."-";
		}

		if($_REQUEST['checkClass9']!="")
		{
			$StrClass1=$StrClass1."?";
		}
		else
		{
			$StrClass1=$StrClass1."-";
		}

		//echo "<p>->".$StrClass1."<p>";

		//----------------------------------


		//SERIE_DUVIDA


		if($_REQUEST['checkSubClass1']!="")
		{
			$StrSubClass1="?";
		}
		else
		{
			$StrSubClass1="-";
		}

		if($_REQUEST['checkSubClass3']!="")
		{
			$StrSubClass1=$StrSubClass1."?";
		}
		else
		{
			$StrSubClass1=$StrSubClass1."-";
		}

		if($_REQUEST['checkSubClass5']!="")
		{
			$StrSubClass1=$StrSubClass1."?";
		}
		else
		{
			$StrSubClass1=$StrSubClass1."-";
		}

		if($_REQUEST['checkSubClass7']!="")
		{
			$StrSubClass1=$StrSubClass1."?";
		}
		else
		{
			$StrSubClass1=$StrSubClass1."-";
		}

		if($_REQUEST['checkSubClass9']!="")
		{
			$StrSubClass1=$StrSubClass1."?";
		}
		else
		{
			$StrSubClass1=$StrSubClass1."-";
		}

		//echo "<p>->".$StrSubClass1."<p>";

		//----------------------------------

		//SECAO_PRI_DUVIDA


		if($_REQUEST['checkClass2']!="")
		{
			$StrClass2="?";
		}
		else
		{
			$StrClass2="-";
		}

		if($_REQUEST['checkClass4']!="")
		{
			$StrClass2=$StrClass2."?";
		}
		else
		{
			$StrClass2=$StrClass2."-";
		}

		if($_REQUEST['checkClass6']!="")
		{
			$StrClass2=$StrClass2."?";
		}
		else
		{
			$StrClass2=$StrClass2."-";
		}

		if($_REQUEST['checkClass8']!="")
		{
			$StrClass2=$StrClass2."?";
		}
		else
		{
			$StrClass2=$StrClass2."-";
		}

		if($_REQUEST['checkClass10']!="")
		{
			$StrClass2=$StrClass2."?";
		}
		else
		{
			$StrClass2=$StrClass2."-";
		}

		//echo "<p>->".$StrClass2."<p>";

		//----------------------------------


		//SECAO_DUVIDA


		if($_REQUEST['checkSubClass2']!="")
		{
			$StrSubClass2="?";
		}
		else
		{
			$StrSubClass2="-";
		}

		if($_REQUEST['checkSubClass4']!="")
		{
			$StrSubClass2=$StrSubClass2."?";
		}
		else
		{
			$StrSubClass2=$StrSubClass2."-";
		}

		if($_REQUEST['checkSubClass6']!="")
		{
			$StrSubClass2=$StrSubClass2."?";
		}
		else
		{
			$StrSubClass2=$StrSubClass2."-";
		}

		if($_REQUEST['checkSubClass8']!="")
		{
			$StrSubClass2=$StrSubClass2."?";
		}
		else
		{
			$StrSubClass2=$StrSubClass2."-";
		}

		if($_REQUEST['checkSubClass10']!="")
		{
			$StrSubClass2=$StrSubClass2."?";
		}
		else
		{
			$StrSubClass2=$StrSubClass2."-";
		}

		//echo "<p>->".$StrSubClass2."<p>";

		//----------------------------------

		//salva imagens no banco
		//ver($_REQUEST,0);
		//ver($_SESSION);
		if($_SESSION['MAD_Formulario']['registro'] == $_REQUEST['Informatizado']
			&& isset($_SESSION['MAD_Formulario']['imgDedos']))
		{
			foreach($_SESSION['MAD_Formulario']['imgDedos'] as $key=>$val)
			{
				$MadDao->alterarImagemDedo($_REQUEST['Informatizado'],$key,$val);
			}
		}
		
		//gera a query para a tabela de analises

		$_REQUEST['seqDirSubClass'] = $seqDirSubClass;
		$_REQUEST['seqDirClass'] = $seqDirClass ;
		$_REQUEST['seqEsqSubClass'] = $seqEsqSubClass;
		$_REQUEST['seqEsqClass'] = $seqEsqClass;
		$_REQUEST['StrClass1'] = $StrClass1;
		$_REQUEST['StrClass2'] = $StrClass2;
		$_REQUEST['StrSubClass1'] = $StrSubClass1;
		$_REQUEST['StrSubClass2'] = $StrSubClass2 ;


		//$_REQUEST['seqEsqPtoCarac'] = $seqEsqPtoCarac;
		//$_REQUEST['seqDirPtoCarac'] = $seqDirPtoCarac;
		ksort($_REQUEST);
		//ver($_REQUEST);
		
		$MadDao->gravarAnalise($_REQUEST);

		$transformer = new Transformer();
		$transformer->setDirFisicoTemplates("template/MAD/");
		$transformer->setArquivoTemplate("ActionSalvarFormulario.htm");
		$transformer->setValoresTroca($valoresTroca);
		$saida = $transformer->processaHTML();
		return $saida;
	}
}

?>
